package com.warm.pump.module.work.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.warm.pump.frame.gen.util.OutJson;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.module.work.bean.po.gen.WorkItemSub;
import com.warm.pump.module.work.service.IWorkItemSubService;
import com.warm.pump.frame.gen.util.MyBeanUtils;

/**
 * work_item_sub
 */
@Controller
@RequestMapping("/workItemSub")
public class WorkItemSubController {
    @Autowired
    private IWorkItemSubService workItemSubService;

    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/list/{id}")
    @RequiresPermissions("workItemSub:list")
    public OutJson list(@PathVariable("id") List<Long> id) {
        Map<String, Object> map = new HashMap<>();
        map.put("itemDtlId_in", id);
        //查询列表数据
        List<WorkItemSub> list = workItemSubService.queryList(map);

        return OutJson.ok().put("list", list);
    }


    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/subList")
    public OutJson subList(Integer page, Integer limit, WorkItemSub workItemSub) {
        if (page == null) {
            page = 1;
        }
        if (limit == null) {
            limit = 999999;
        }
        Map<String, Object> map = new HashMap<>();
        if (null == workItemSub.getItemId()) {
            workItemSub.setItemId(99999999999999l);
        }
        MyBeanUtils.copyBean2Map(map, workItemSub);
        map.put("orderBy", "order_num");
        //查询列表数据
        PageBean pageBean = workItemSubService.getPageBeanByMap(map, page, limit);

        return OutJson.ok().put("page", pageBean);
    }


    /**
     * 信息
     */
    @ResponseBody
    @RequestMapping("/info/{id}")
    @RequiresPermissions("workItemSub:info")
    public OutJson info(@PathVariable("id") Long id) {
        WorkItemSub workItemSub = workItemSubService.queryObject(id);

        return OutJson.ok().put("workItemSub", workItemSub);
    }


    /**
     * 保存
     */
    @ResponseBody
    @RequestMapping("/save")
    @RequiresPermissions("workItemSub:save")
    public OutJson save(@RequestBody WorkItemSub WorkItemSub) {
        workItemSubService.save(WorkItemSub);

        return OutJson.ok();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("workItemSub:update")
    public OutJson update(@RequestBody WorkItemSub WorkItemSub) {
        workItemSubService.update(WorkItemSub);

        return OutJson.ok();
    }

    /**
     * 删除
     */
    @ResponseBody
    @RequestMapping("/delete")
    @RequiresPermissions("workItemSub:delete")
    public OutJson delete(@RequestBody Long[] ids) {
        workItemSubService.deleteBatch(ids);

        return OutJson.ok();
    }

}
